Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove resolver.UnregisterForTesting usage #417

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

bananacocodrilo
Copy link

resolver.UnregisterForTesting has been removed from grpc-go grpc/grpc-go#6471, this change is needed in order to update to grpc 1.59.0

@CLAassistant
Copy link

CLAassistant commented Sep 24, 2024

CLA assistant check
All committers have signed the CLA.

@@ -32,8 +32,7 @@ type ReflectionArgs struct {
// NewDescriptorProviderReflection returns a DescriptorProvider that reaches
// out to a reflection server to access file descriptors.
func NewDescriptorProviderReflection(args ReflectionArgs) (DescriptorProvider, error) {
r, deregisterScheme := GenerateAndRegisterManualResolver()
defer deregisterScheme()
r := GenerateAndRegisterManualResolver()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're creating potential memory leak here.
Let's discuss potential solution with a custom resolver, i.e. to register only one resolver, and then reuse it for different services.

Copy link
Author

@bananacocodrilo bananacocodrilo Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into two options to address it:

Keep the manual resolver.

We can create the scheme deterministically (I'm thinking scheme = "dest-" + args.Service).
This allows us to use resolver.Get(scheme) to avoid creating unnecessary resolvers, and we also can keep an updated the list of peers in the resolver.

Use passthrough

This results in simpler code, but only allows to specify one peer.
If the peer-list file used contains outdated addresses this could make the reflection fail where otherwise it would have worked.


rb := resolver.Get(scheme)
if rb != nil {
if r, ok := rb.(*manual.Resolver); ok {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual resolvers implement both, Resolver and Builder.
r.InitialState(newState) will set the new list of peers the next time that Build is called

@@ -196,6 +196,44 @@ func TestReflectionRoutingHeaders(t *testing.T) {
}
}

func TestResolverAlreadyExists(t *testing.T) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test creating a new resolver for the same service with a different list of peers

rb := resolver.Get(scheme)
if rb != nil {
if r, ok := rb.(*manual.Resolver); ok {
r.InitialState(newState)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InitialState doesn't use mutex inside, so it's a potential data race.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants